/**
 * 
 */
package com.yst.metho.web.application.pointage;

import java.text.MessageFormat;

import nextapp.echo2.app.Component;
import nextapp.echo2.app.Label;
import nextapp.echo2.app.Table;
import nextapp.echo2.app.table.TableCellRenderer;

import com.yst.suivi.data.pointage.Pointage;

/**
 * @author perso
 * 
 */
public class MyActivityCellRenderer implements TableCellRenderer
{
	private final String MSG = "{0}/{1}\n{2}";

	/*
	 * (non-Javadoc)
	 * 
	 * @see nextapp.echo2.app.table.TableCellRenderer#getTableCellRendererComponent(nextapp.echo2.app.Table,
	 *      java.lang.Object, int, int)
	 */
	public Component getTableCellRendererComponent(Table table, Object value, int column, int row)
	{
		Label lbl;
		if (null == value)
		{
			lbl = new Label("");
		}
		else
		{
			if (column == 0)
			{
				lbl = new Label(value.toString());
			}
			else
			{
				Object[] params = new Object[3];
				Pointage pointage = (Pointage) value;
				if (null != pointage.getActivity().getProject())
				{
					params[0] = pointage.getActivity().getProject().getNom();
					params[1] = pointage.getActivity().getProjectVersion().getVersion();
					params[2] = pointage.getActivity().getNom();
					lbl = new Label(MessageFormat.format(MSG, params));
				}
				else
				{
					lbl = new Label(pointage.getActivity().getNom());
				}
			}
		}
		return lbl;
	}

}
